package edu.xust.controller.api;


import com.alibaba.fastjson.JSON;
import edu.xust.dto.AdDto;
import edu.xust.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api")
public class ApiController {
    @Autowired
    private AdService adService;
    @Value("${ad.number}")//读取配置文件中的条目
    private int adnumber;
    //显示广告
    @RequestMapping(value="/homead",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public String homead() throws IOException {
        AdDto adDto = new AdDto();
        adDto.getPage().setPageNumber(adnumber);
        String adApi = JSON.toJSONString(adService.searchByPage(adDto));
        return  adApi;
    }
}
